/**
 * 封装localstorage 序列化方法
 */

/**
 *  反序列化
 */
export const setItem = (key, value) => {
  if (typeof value === 'object') {
    value = JSON.stringify(value)
  }
  window.localStorage.setItem(key, value)
}

/**
   *  序列化
   */
export const getItem = (key) => {
  const val = window.localStorage.getItem(key)
  try {
    return JSON.parse(val)
  } catch (error) {
    return val
  }
}

/**
   *  删除
   */
export const removeItem = (key) => {
  window.localStorage.removeItem(key)
}
